<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>地图标点</title>
<link href="../favicon.ico" type="image/x-icon" rel="icon" />
<link href="../favicon.ico" type="image/x-icon" rel="shortcut icon" />
<!-- baidu api js -->
<script type="text/javascript" language="javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
<link href="../js/Prompt/skin/ymPrompt.css" id='skin' rel="stylesheet" type="text/css"/>
<script language="javascript" charset="utf-8" type="text/javascript" src="../js/Prompt/ymPrompt.js"></script>

<style rel="stylesheet" type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-size:12px;background:#C4D8ED;}
#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
.btn{
	BORDER-RIGHT: #0daf0f 1px solid;PADDING-RIGHT: 2px;	BORDER-TOP: #0daf0f 1px solid;
	PADDING-LEFT: 2px;font-weight:800;font-family:Courier;FONT-SIZE: 12px;background-color:#079009;
	BORDER-LEFT: #0daf0f 1px solid;	CURSOR:pointer;	COLOR: #FFFFFF;	PADDING-TOP: 2px;BORDER-BOTTOM: #0daf0f 1px solid
}
.put{
	border: 1px solid #AEC0CD;
	width:200px;
	height:22px;
	line-height:20px;
	size:18px;
	color:#000000;
	background:repeat-x top #FFF;
}
</style>
</head>
<body>
<div id="allmap">
<div id="l-map"></div>
<div id="r-result">
<span>输入关键字:</span>
<input type="text" id="suggestId" size="20" value="快速查找..." onfocus='if(this.value=="快速查找..."){this.value=""}' onblur='if(this.value==""){this.value="快速查找..."}' class="put" />
<br/>
<input type="button" onclick="saveLnglat();" class="btn" value="&nbsp;确定选择&nbsp;"/>
</div>
<div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto;"></div>
</div>
</body>
</html>
<?php 
$lng=trim(empty($_REQUEST['lng'])?"":$_REQUEST['lng']);
$lat=trim(empty($_REQUEST['lat'])?"":$_REQUEST['lat']);
$word=trim(empty($_REQUEST['word'])?"上海":$_REQUEST['word']);
?>
<script type="text/javascript" language="javascript">
var map = new BMap.Map("l-map");
var myIcon = new BMap.Icon("../images/mapsA.png", new BMap.Size(20, 32), {anchor: new BMap.Size(10, 30)});

<?php if($lat && $lat){?>
//有坐标
var point = new BMap.Point("<?php echo $lng;?>", "<?php echo $lat;?>");
map.centerAndZoom(point, 15);
var marker = new BMap.Marker(point, {
	icon : myIcon,
	enableDragging: true
});
<?php }else{?>
//有城市
map.centerAndZoom("<?php echo $word;?>",15);
var point = new BMap.Point("121.4", "31.2");
var marker = new BMap.Marker(point, {
	icon : myIcon,
	enableDragging: true
});
<?php }?>
marker.enableDragging();
map.addOverlay(marker);

//添加默认缩放平移控件
map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.ScaleControl());//添加比例尺控件
map.addControl(new BMap.OverviewMapControl());//添加缩略地图控件
map.enableScrollWheelZoom();//启用滚轮放大缩小，默认禁用
map.enableContinuousZoom();//启用地图惯性拖拽，默认禁用

//点击获取坐标
map.addEventListener("click",function(e){
	var point = new BMap.Point(e.point.lng, e.point.lat);
	new BMap.Marker(point, {
		icon : myIcon
	});
	
});

var ac = new BMap.Autocomplete(
	    {"input" : "suggestId"
	    ,"location" : map
	});
//鼠标放在下拉列表上的事件
ac.addEventListener("onhighlight", function(e) {
	var str = "";
    var _value = e.fromitem.value;
    var value = "";
    if (e.fromitem.index > -1) {
        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    }    
    str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
    
    value = "";
    if (e.toitem.index > -1) {
        _value = e.toitem.value;
        value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    }    
    str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
    document.getElementById("searchResultPanel").innerHTML = str;
});

var myValue;
//鼠标点击下拉列表后的事件
ac.addEventListener("onconfirm", function(e) {    
var _value = e.item.value;
    myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
    document.getElementById("searchResultPanel").innerHTML ="onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
    setPlace();
});

function setPlace(){
	//清除地图上所有覆盖物
    map.clearOverlays();
    function myFun(){
		//获取第一个智能搜索的结果
        var pp = local.getResults().getPoi(0).point;
        map.setCenter(pp);

     	marker = new BMap.Marker(pp, {
     		icon : myIcon
     	});

     	marker.enableDragging();
        map.addOverlay(marker);//添加标注
    }
    var local = new BMap.LocalSearch(map, { //智能搜索
      onSearchComplete: myFun
    });
    local.search(myValue);
}

function saveLnglat(){
	//alert(marker.getPosition().lng + "," + marker.getPosition().lat);
	if(marker.getPosition().lng && marker.getPosition().lat){
		ymPrompt.confirmInfo({title:'系统提示',message:'确定选择当前坐标',handler:function(tp){if(tp=='ok'){window.opener.add_latlng("lat",marker.getPosition().lat,"lng",marker.getPosition().lng);self.close();}else{}}});	
	}else{
		ymPrompt.errorInfo({title:'系统提示',message:'获取当前坐标失败'});
	}
}
</script>

